import os
import shlex

import lorun
import config


def run():
    cmd = 'java -cp %s Main' % (os.path.join(config.work_dir, str(001)))
    print (cmd)
    main_exe = shlex.split(cmd)
    print (main_exe)
    data_num = "1"
    input_path = os.path.join(config.data_dir, str(001), 'data%s.in' % data_num)
    print (input_path)
    input_data = file(input_path)
    output_path = os.path.join(config.work_dir, str(001), 'out%s.txt' % data_num)
    print (output_path)
    temp_out_data = file(output_path, 'w')
    run_conf = {
        'args': main_exe,
        'fd_in': input_data.fileno(),
        'fd_out': temp_out_data.fileno(),
        'timelimit': 1000,  # in MS
        'memorylimit': 512000,  # in KB
    }
    print (run_conf)
    rst = lorun.run(run_conf)
    print(rst)
    return


run()